<!--
  Copyright 2016 The LUCI Authors. All rights reserved.
  Use of this source code is governed under the Apache License, Version 2.0
  that can be found in the LICENSE file.
-->

<script>
  'use strict';

  var luci = (function(luci) {

    var rpc = luci.rpc = luci.rpc || {};

    /**
     * gRPC response codes.
     * based on https://github.com/grpc/grpc-go/blob/972dbd2/codes/codes.go#L43
     * @enum {number}
     */
    rpc.Code = {
      OK: 0,
      CANCELED: 1,
      UNKNOWN: 2,
      INVALID_ARGUMENT: 3,
      DEADLINE_EXCEEDED: 4,
      NOT_FOUND: 5,
      ALREADY_EXISTS: 6,
      PERMISSION_DENIED: 7,
      UNAUTHENTICATED: 16,
      RESOURCE_EXHAUSTED: 8,
      FAILED_PRECONDITION: 9,
      ABORTED: 10,
      OUT_OF_RANGE: 11,
      UNIMPLEMENTED: 12,
      INTERNAL: 13,
      UNAVAILABLE: 14,
      DATA_LOSS: 15
    };

    var codeNames = {};
    for (var name in rpc.Code) {
      codeNames[rpc.Code[name]] = name;
    }

    /**
     * Returns response code name or undefined.
     */
    rpc.CodeName = function(code) {
      return codeNames[code];
    };

    return luci;
  }(luci || {}));
</script>
